package com.yu.subject.domain.handler.subject;

import com.yu.subject.common.enums.SubjectInfoTypeEnum;
import com.yu.subject.domain.entity.SubjectAnswerBO;
import com.yu.subject.domain.entity.SubjectInfoBO;
import com.yu.subject.domain.entity.SubjectOptionBO;
import com.yu.subject.infra.basic.entity.SubjectJudge;
import com.yu.subject.infra.basic.entity.SubjectMultiple;
import com.yu.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 路亚
 * @version 0.1
 * @className RadioTypeHandler
 * @description
 * @date 2024/12/24 22:32
 * @since jdk11
 */
@Component
public class JudgeTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectJudgeService subjectJudgeService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        // 插入
        List<SubjectAnswerBO> optionList = subjectInfoBO.getOptionList();
        List<SubjectJudge> list = optionList.stream().map(option -> {
            SubjectJudge subjectJudge = new SubjectJudge();
            BeanUtils.copyProperties(option, subjectJudge);
            subjectJudge.setSubjectId(subjectInfoBO.getId());
            return subjectJudge;
        }).collect(Collectors.toList());
        subjectJudgeService.saveBatch(list);
    }

    @Override
    public SubjectOptionBO query(Integer subjectId) {
        return null;
    }
}
